package com.xiaoqi.store.controller;

import com.xiaoqi.store.entity.JsonResult;
import com.xiaoqi.store.entity.ProductEntity;
import com.xiaoqi.store.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Rookie Coder
 * @Description
 * @Date
 **/
@RestController
@RequestMapping("/products")
@Slf4j
public class ProductController extends BaseController{

    @Autowired
    private ProductService productService;

    /*
    * @Author xiaoqi
    * @Description  查询热销商品
    * @return JsonResult<List<ProductEntity>>
    **/
    @GetMapping("/hot_list")
    public JsonResult<List<ProductEntity>> getHotProduct(){
        List<ProductEntity> productEntities = productService.selectAllHotProduct();
        log.info("查询到热销商品，并成功返回");
        return new JsonResult<>(OK,productEntities);
    }

    /*
    * @Author xiaoqi
    * @Description  查询商品详情
    * @return  JsonResult<ProductEntity>
    **/
    @GetMapping("{id}/details")
    public JsonResult<ProductEntity> selectProductDetails( @PathVariable Integer id) {
        ProductEntity  productDetails = productService.selectProductDetails(id);
        return new JsonResult<>(OK,productDetails);
    }
}
